package b3.widget.guide
{
	import b3.net.*;
	import b3.util.*;
	import b3.widget.basic.*;
	
	import com.greensock.*;
	
	import flash.display.*;
	import flash.events.*;
	import flash.filters.*;
	import flash.text.*;
	
	public class NpcDialog extends BasicWidget
	{
		public var talkDialog:TalkDialog;
		private var npcImg:Sprite;
		
		public function NpcDialog(npcImgName:String, content:Array)
		{
			super();
			//NPC
			var NpcImg:Class = ResourceHelper.getInstance().getClassByName(npcImgName);
			npcImg = new NpcImg();
			npcImg.y = npcImg.height;
			addChild(npcImg);
			//对话框背景
			talkDialog = new TalkDialog("NpcDialogBgr1", content);
			talkDialog.x = -talkDialog.width + 30;
			talkDialog.y = -npcImg.height * 0.65;
			addChild(talkDialog);

			this.addEventListener(Event.ADDED_TO_STAGE, onAddedToStage);
			this.addEventListener(Event.REMOVED_FROM_STAGE, onRemovedFromStage);
			talkDialog.addEventListener(Event.REMOVED_FROM_STAGE, onDialogRemovedFromStage);
		}
		
		private function onAddedToStage(event:Event):void
		{
			TweenLite.to(npcImg, 0.5, {y: 0});
			stage.addEventListener(Event.FULLSCREEN, onFullScreen);
			onFullScreen(null); 
		}

		private function onRemovedFromStage(event:Event):void
		{
			stage.removeEventListener(Event.FULLSCREEN, onFullScreen);
		}
		
		private function onDialogRemovedFromStage(event:Event):void
		{
			TweenLite.to(npcImg, 0.5, {y: npcImg.height, onComplete:close});
		}
	
		private function onFullScreen(event:Event):void
		{
			this.y = BFont.stageHeight;
			this.x = BFont.stageWidth / 2 + 70;
		}
		
	}
}